<template>
	<view class="container">
		<view >
		<button type="primary"  size="mini" @click="add_coupon">添加优惠券</button>	
		</view>
	
		<view class="quan" >
		<view class="quanInfo" v-for="(item,i) in couponList" :key="i">
			<text class="couponMpoey">{{item.mjqfd}}<text class="couponMpoeyInfo">满{{item.mjqqsje}}减{{item.mjqfd}}</text></text>
			<text class="couponName">优惠劵</text>
			<text class="couponName">优惠范围：{{item.sytype}}</text>
			<text class="couponTime">{{item.mjqqssj}}-{{item.mjqjssj}}</text>
			<view >
				<button  size="mini" @click="distribute_coupon(item.yhqID)">派发</button>
				<button class="coppon_right" size="mini" type="warn" @click="delete_coupon(item.yhqID)">删除</button>
			</view>
		</view>
		</view>
	</view>
</template>

<script>
import {BASE_URL} from '../../api/ajax.js'
import {myRequest} from '../../api/ajax.js'
import { createNamespacedHelpers } from 'vuex'
const { mapState, mapActions, mapGetters } = createNamespacedHelpers('goods')

export default {
	data() {
		return {
			mytypes:[],
			againFresh:'',
			}
		},
	watch: {
		//监听reFresh,如果有修改就执行监听器
		againFresh: function() {
	        //调接口刷新数据
		
			this.$store.dispatch('goods/get_type')
		}
	},
	computed: {
		...mapGetters(['couponList']),
	},
	methods:{
		add_coupon(){
			uni.navigateTo({
				url:'/pages/addCoupon/addCoupon'
			})
		},
		/* refer_coupon(){
			uni.request({
					// url:options.url,
					url:BASE_URL+'/newtest/shop-mjq/selectAllmjq/1001',
					method: 'GET',
					success: (res)=>{
						console.log(res.data.data.res)
						this.couponList = res.data.data.res
						uni.hideLoading()
					},
					fail: (err)=>{
						uni.showToast({
							title: '请求接口失败'
						})
						reject(err)
					}})
		}, */
		distribute_coupon(id){
			uni.request({
					// url:options.url,
					url:BASE_URL+'/newtest/shop-mjq/postmjq/'+id,
					method: 'GET',
					success: (res)=>{
						console.log(res.data)
						if(res.data.success)
						uni.showToast({
							title:'派发成功'
						})
						uni.hideLoading()
					},
					fail: (err)=>{
						uni.showToast({
							title: '请求接口失败'
						})
						reject(err)
					}})
		},
	async delete_coupon(id){
				console.log('delete_goods',id)
				uni.showModal({
				    title: '提示',
				    content: '您确定要删除吗',
				    success: (res)=> {
						console.log(res)
				        if (res.confirm) {
				            console.log('用户点击确定');
						
						this.$request({
								url:'/newtest/shop-mjq/deleteByID/'+id,
								method:"DELETE",
							}).then((res)=>{
								console.log('res',res)
								this.$store.dispatch('goods/get_type')
							})
				        }
				    }
				})
				
				
			},
	},
	onLoad() {
		this.$store.dispatch('goods/get_type')
		// this.refer_coupon()
	}
		
		}
</script>

<style>
.container{
	position:relative ;
}
.quan{
		margin: 22rpx 37rpx;
		background-color: #FFF5F6;
		border-radius: 10rpx;
		font-family: PingFang SC;
	}
	.quanInfo{
		background-image: radial-gradient(circle at right top, #FFFFFF, #FFFFFF 15rpx, transparent 16rpx), radial-gradient(circle at right bottom, #FFFFFF, #FFFFFF 15rpx, transparent 16rpx);
		border-right: 1px dashed #F64F51;
		padding: 30rpx 50rpx;
		width: 75%;
	}
	.couponMpoey{
		font-size: 30rpx;
		font-weight: 700;
		color: #ff3600;
		display: block;
	}
	.couponMpoeyInfo{
		font-size: 26rpx;
		padding-left: 10rpx;
	}
	.couponName{
		font-size: 24rpx;
		font-weight: 500;
		color: #797979;
		display: block;
	}
	.couponTime{
		font-size: 20rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #797979;
	}
	.receiveBtn{
		background-image: radial-gradient(circle at left top, #FFFFFF, #FFFFFF 15rpx, transparent 16rpx), radial-gradient(circle at left bottom, #FFFFFF, #FFFFFF 15rpx, transparent 16rpx);
		display: flex;
		align-items: center;
		justify-content: center;
		margin-left: -2rpx;
	}
	.receive{
		border-radius: 23rpx;
		background-color: #5FC484;
		padding: 7rpx 31rpx;
		text-align: center;
		margin-left: 36rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
	}
	.coppon_right{
		float: right;
	}
</style>
